/**************************************************
  File: src/xacontrol.c
  Description: Audio Cup XAudio Control ( object )
  Author: Brant Anderson
  Date: 10/25/01
  Last Update: 10/29/01
  Staus: Working
  To Do:
 **************************************************/



#include <stdio.h>
#include "../include/xacontrol.h"



/** creates an XAudio player object **/
XA_Control *getXAPlayer( ) {

	XA_Control *xaPlayer;

	/** create a new XA player **/
	if( player_new( &xaPlayer, NULL ) == XA_SUCCESS ) {
		printf("getXAPlayer: Success\n");
		return xaPlayer;
	} else {
		printf("getXAPlayer: Fail\n");
		return NULL;
	}

}

void openXA( XA_Control *xaPlayer, char *filename ) {

	if( control_message_send( xaPlayer, XA_MSG_COMMAND_INPUT_OPEN, filename ) == XA_SUCCESS )
		printf( "openXA: Success\n" );
	else
		printf( "openXA: Fail\n" );

}

void playXA( XA_Control *xaPlayer ) {

	if( control_message_send( xaPlayer, XA_MSG_COMMAND_PLAY ) == XA_SUCCESS )
		printf( "playXA: Success\n" );
	else
		printf( "playXA: Fail\n" );

}

void pauseXA( XA_Control *xaPlayer ) {

	if( control_message_send( xaPlayer, XA_MSG_COMMAND_PAUSE ) == XA_SUCCESS )
		printf("pauseXA: Success\n");
	else
		printf("pauseXA: Fail\n");

}

void stopXA( XA_Control *xaPlayer ) {

	if( control_message_send( xaPlayer, XA_MSG_COMMAND_INPUT_CLOSE ) == XA_SUCCESS )
		printf( "stopXA: Success\n" );
	else
		printf( "stopXA: Fail\n" );

}

void seekXA( XA_Control *xaPlayer, unsigned short offset ) {

	if( control_message_send( xaPlayer, XA_MSG_COMMAND_SEEK, offset, 100 ) == XA_SUCCESS )
		printf( "seekXA: Success\n" );
	else
		printf( "seekXA: Fail\n" );

}

void exitXA( XA_Control *xaPlayer ) {

	if( control_message_send( xaPlayer, XA_MSG_COMMAND_EXIT ) == XA_SUCCESS )
		printf( "exitXA: Success\n" );
	else
		printf( "exitXA: Fail\n" );

}

int getXAMessage( XA_Control *xaPlayer, XA_Message *xaMessage ) {

	int status;
	status = control_message_get( (void*)xaPlayer, xaMessage );
	return status;

}
